
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/18/2011 00:02:19
-- Generated from EDMX file: H:\Project2010\FastTravel\FastTravel.DB\FastTravelModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [FastTravel];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CountryResort]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Resort] DROP CONSTRAINT [FK_CountryResort];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderOrderPrice_Order]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderOrderPrice] DROP CONSTRAINT [FK_OrderOrderPrice_Order];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderOrderPrice_OrderPrice]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderOrderPrice] DROP CONSTRAINT [FK_OrderOrderPrice_OrderPrice];
GO
IF OBJECT_ID(N'[dbo].[FK_UserOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order] DROP CONSTRAINT [FK_UserOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomerPassport]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Passport] DROP CONSTRAINT [FK_CustomerPassport];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderOrderHistory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderHistory] DROP CONSTRAINT [FK_OrderOrderHistory];
GO
IF OBJECT_ID(N'[dbo].[FK_ResortHotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Hotel] DROP CONSTRAINT [FK_ResortHotel];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderHotel_Order]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderHotel] DROP CONSTRAINT [FK_OrderHotel_Order];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderHotel_Hotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderHotel] DROP CONSTRAINT [FK_OrderHotel_Hotel];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderContragent_Order]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderContragent] DROP CONSTRAINT [FK_OrderContragent_Order];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderContragent_TravelAgency]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderContragent] DROP CONSTRAINT [FK_OrderContragent_TravelAgency];
GO
IF OBJECT_ID(N'[dbo].[FK_ServiceGroupService]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Service] DROP CONSTRAINT [FK_ServiceGroupService];
GO
IF OBJECT_ID(N'[dbo].[FK_ServiceForHotelService_ServiceForHotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ServiceForHotelService] DROP CONSTRAINT [FK_ServiceForHotelService_ServiceForHotel];
GO
IF OBJECT_ID(N'[dbo].[FK_ServiceForHotelService_Service]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ServiceForHotelService] DROP CONSTRAINT [FK_ServiceForHotelService_Service];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelServiceForHotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ServiceForHotel] DROP CONSTRAINT [FK_HotelServiceForHotel];
GO
IF OBJECT_ID(N'[dbo].[FK_ServiceServiceVariant]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ServiceVariant] DROP CONSTRAINT [FK_ServiceServiceVariant];
GO
IF OBJECT_ID(N'[dbo].[FK_HotelHotelPhoto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HotelPhoto] DROP CONSTRAINT [FK_HotelHotelPhoto];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomerScan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Scan] DROP CONSTRAINT [FK_CustomerScan];
GO
IF OBJECT_ID(N'[dbo].[FK_ResortResortPhoto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ResortPhoto] DROP CONSTRAINT [FK_ResortResortPhoto];
GO
IF OBJECT_ID(N'[dbo].[FK_RelatredHotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Hotel] DROP CONSTRAINT [FK_RelatredHotel];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderDestinationPoint]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DestinationPoint] DROP CONSTRAINT [FK_OrderDestinationPoint];
GO
IF OBJECT_ID(N'[dbo].[FK_DestinationPointHotel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Hotel] DROP CONSTRAINT [FK_DestinationPointHotel];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomerOrderSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderSet] DROP CONSTRAINT [FK_CustomerOrderSet];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderOrderSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderSet] DROP CONSTRAINT [FK_OrderOrderSet];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User];
GO
IF OBJECT_ID(N'[dbo].[Customer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Customer];
GO
IF OBJECT_ID(N'[dbo].[Order]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order];
GO
IF OBJECT_ID(N'[dbo].[Country]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Country];
GO
IF OBJECT_ID(N'[dbo].[Resort]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Resort];
GO
IF OBJECT_ID(N'[dbo].[Hotel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Hotel];
GO
IF OBJECT_ID(N'[dbo].[Passport]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Passport];
GO
IF OBJECT_ID(N'[dbo].[OrderPrice]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderPrice];
GO
IF OBJECT_ID(N'[dbo].[OrderHistory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderHistory];
GO
IF OBJECT_ID(N'[dbo].[TravelAgency]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TravelAgency];
GO
IF OBJECT_ID(N'[dbo].[ServiceGroup]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ServiceGroup];
GO
IF OBJECT_ID(N'[dbo].[Service]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Service];
GO
IF OBJECT_ID(N'[dbo].[ServiceForHotel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ServiceForHotel];
GO
IF OBJECT_ID(N'[dbo].[ServiceVariant]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ServiceVariant];
GO
IF OBJECT_ID(N'[dbo].[HotelPhoto]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HotelPhoto];
GO
IF OBJECT_ID(N'[dbo].[Scan]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Scan];
GO
IF OBJECT_ID(N'[dbo].[ResortPhoto]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ResortPhoto];
GO
IF OBJECT_ID(N'[dbo].[DestinationPoint]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DestinationPoint];
GO
IF OBJECT_ID(N'[dbo].[OrderSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderSet];
GO
IF OBJECT_ID(N'[dbo].[OrderOrderPrice]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderOrderPrice];
GO
IF OBJECT_ID(N'[dbo].[OrderHotel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderHotel];
GO
IF OBJECT_ID(N'[dbo].[OrderContragent]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderContragent];
GO
IF OBJECT_ID(N'[dbo].[ServiceForHotelService]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ServiceForHotelService];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Login] nvarchar(max)  NOT NULL,
    [PasswordHash] nvarchar(max)  NOT NULL,
    [PasswordSalt] nvarchar(max)  NOT NULL,
    [IsBlocked] bit  NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [MiddleName] nvarchar(max)  NOT NULL,
    [UserRoleProperty] int  NOT NULL,
    [IsArchive] bit  NOT NULL,
    [AddedDate] datetime  NOT NULL,
    [IsOnline] bit  NOT NULL
);
GO

-- Creating table 'Customer'
CREATE TABLE [dbo].[Customer] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [MiddleName] nvarchar(max)  NOT NULL,
    [MaritalStatusProperty] int  NOT NULL,
    [PhoneHome] bigint  NOT NULL,
    [PhoneMobile] bigint  NOT NULL,
    [PhoneWork] bigint  NOT NULL,
    [Profession] nvarchar(max)  NOT NULL,
    [JobPlacement] nvarchar(max)  NOT NULL,
    [IsArchive] bit  NOT NULL,
    [AddedDate] datetime  NOT NULL,
    [BirthDate] datetime  NOT NULL,
    [AddressLine1] nvarchar(max)  NOT NULL,
    [AddressLine2] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [ModifyDate] datetime  NOT NULL
);
GO

-- Creating table 'Order'
CREATE TABLE [dbo].[Order] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [OrderStatusProperty] int  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [ProcessedDate] datetime  NOT NULL,
    [HotelFoodProperty] int  NOT NULL,
    [AppartamentTypeProperty] int  NOT NULL,
    [DateFrom] datetime  NOT NULL,
    [DateTo] datetime  NOT NULL,
    [OrderNumber] nvarchar(max)  NOT NULL,
    [Transport] nvarchar(max)  NOT NULL,
    [LastEditDate] datetime  NOT NULL,
    [TransportAdditional] nvarchar(max)  NOT NULL,
    [User_ID] int  NULL
);
GO

-- Creating table 'Country'
CREATE TABLE [dbo].[Country] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [ISO] int  NOT NULL
);
GO

-- Creating table 'Resort'
CREATE TABLE [dbo].[Resort] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [AddedDate] datetime  NOT NULL,
    [Country_ID] int  NULL
);
GO

-- Creating table 'Hotel'
CREATE TABLE [dbo].[Hotel] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IsArchive] bit  NOT NULL,
    [RestorationYear] int  NOT NULL,
    [BuildYear] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [RoomsCount] int  NOT NULL,
    [RoomsCategory] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [AddedDate] datetime  NOT NULL,
    [StarLevel] int  NOT NULL,
    [FloorCount] int  NOT NULL,
    [Resort_ID] int  NULL,
    [NearestHotel_ID] int  NULL,
    [DestinationPoint_ID] int  NULL
);
GO

-- Creating table 'Passport'
CREATE TABLE [dbo].[Passport] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Number] nvarchar(max)  NOT NULL,
    [Authority] nvarchar(max)  NOT NULL,
    [IssueDate] datetime  NOT NULL,
    [ExpiryDate] datetime  NOT NULL,
    [Customer_ID] int  NULL
);
GO

-- Creating table 'OrderPrice'
CREATE TABLE [dbo].[OrderPrice] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Currency] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'OrderHistory'
CREATE TABLE [dbo].[OrderHistory] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ActionDate] datetime  NOT NULL,
    [ActionTypeProperty] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [Order_ID] int  NULL
);
GO

-- Creating table 'TravelAgency'
CREATE TABLE [dbo].[TravelAgency] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [URL] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Phone1] int  NOT NULL,
    [Phone2] int  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [AddressLine1] nvarchar(max)  NOT NULL,
    [AddressLine2] nvarchar(max)  NOT NULL,
    [AddedDate] datetime  NOT NULL
);
GO

-- Creating table 'ServiceGroup'
CREATE TABLE [dbo].[ServiceGroup] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Service'
CREATE TABLE [dbo].[Service] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Tips] nvarchar(max)  NOT NULL,
    [ServiceGroup_ID] int  NULL
);
GO

-- Creating table 'ServiceForHotel'
CREATE TABLE [dbo].[ServiceForHotel] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [PayedProperties] int  NOT NULL,
    [Hotel_ID] int  NULL
);
GO

-- Creating table 'ServiceVariant'
CREATE TABLE [dbo].[ServiceVariant] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Service_ID] int  NULL
);
GO

-- Creating table 'HotelPhoto'
CREATE TABLE [dbo].[HotelPhoto] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Original] nvarchar(max)  NOT NULL,
    [Medium] nvarchar(max)  NOT NULL,
    [Small] nvarchar(max)  NOT NULL,
    [Hotel_ID] int  NULL
);
GO

-- Creating table 'Scan'
CREATE TABLE [dbo].[Scan] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [AddedDate] datetime  NOT NULL,
    [Customer_ID] int  NULL
);
GO

-- Creating table 'ResortPhoto'
CREATE TABLE [dbo].[ResortPhoto] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Original] nvarchar(max)  NOT NULL,
    [Medium] nvarchar(max)  NOT NULL,
    [Small] nvarchar(max)  NOT NULL,
    [AddedDate] datetime  NOT NULL,
    [Resort_ID] int  NULL
);
GO

-- Creating table 'DestinationPoint'
CREATE TABLE [dbo].[DestinationPoint] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [DestinationTypeProperty] int  NOT NULL,
    [DateAtPoint] datetime  NOT NULL,
    [NightDays] nvarchar(max)  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [Order_ID] int  NULL
);
GO

-- Creating table 'OrderSet'
CREATE TABLE [dbo].[OrderSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IsOwner] bit  NOT NULL,
    [TourServicePrice] float  NOT NULL,
    [OrderTourServiceCurrencyProperty] int  NOT NULL,
    [TicketPrice] float  NOT NULL,
    [OrderTicketCurrencyProperty] int  NOT NULL,
    [InsurancePrice] int  NOT NULL,
    [OrderInsuranceCurrencyProperty] float  NOT NULL,
    [VisaPrice] float  NOT NULL,
    [OrderVisaCurrencyProperty] int  NOT NULL,
    [Customer_ID] int  NULL,
    [Order_ID] int  NULL
);
GO

-- Creating table 'OrderOrderPrice'
CREATE TABLE [dbo].[OrderOrderPrice] (
    [Order_ID] int  NOT NULL,
    [OrderPrice_ID] int  NOT NULL
);
GO

-- Creating table 'OrderHotel'
CREATE TABLE [dbo].[OrderHotel] (
    [Order_ID] int  NOT NULL,
    [Hotel_ID] int  NOT NULL
);
GO

-- Creating table 'OrderContragent'
CREATE TABLE [dbo].[OrderContragent] (
    [Order_ID] int  NOT NULL,
    [Contragent_ID] int  NOT NULL
);
GO

-- Creating table 'ServiceForHotelService'
CREATE TABLE [dbo].[ServiceForHotelService] (
    [ServiceForHotel_ID] int  NOT NULL,
    [Service_ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Customer'
ALTER TABLE [dbo].[Customer]
ADD CONSTRAINT [PK_Customer]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Order'
ALTER TABLE [dbo].[Order]
ADD CONSTRAINT [PK_Order]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Country'
ALTER TABLE [dbo].[Country]
ADD CONSTRAINT [PK_Country]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Resort'
ALTER TABLE [dbo].[Resort]
ADD CONSTRAINT [PK_Resort]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Hotel'
ALTER TABLE [dbo].[Hotel]
ADD CONSTRAINT [PK_Hotel]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Passport'
ALTER TABLE [dbo].[Passport]
ADD CONSTRAINT [PK_Passport]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'OrderPrice'
ALTER TABLE [dbo].[OrderPrice]
ADD CONSTRAINT [PK_OrderPrice]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'OrderHistory'
ALTER TABLE [dbo].[OrderHistory]
ADD CONSTRAINT [PK_OrderHistory]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TravelAgency'
ALTER TABLE [dbo].[TravelAgency]
ADD CONSTRAINT [PK_TravelAgency]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ServiceGroup'
ALTER TABLE [dbo].[ServiceGroup]
ADD CONSTRAINT [PK_ServiceGroup]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Service'
ALTER TABLE [dbo].[Service]
ADD CONSTRAINT [PK_Service]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ServiceForHotel'
ALTER TABLE [dbo].[ServiceForHotel]
ADD CONSTRAINT [PK_ServiceForHotel]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ServiceVariant'
ALTER TABLE [dbo].[ServiceVariant]
ADD CONSTRAINT [PK_ServiceVariant]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'HotelPhoto'
ALTER TABLE [dbo].[HotelPhoto]
ADD CONSTRAINT [PK_HotelPhoto]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Scan'
ALTER TABLE [dbo].[Scan]
ADD CONSTRAINT [PK_Scan]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ResortPhoto'
ALTER TABLE [dbo].[ResortPhoto]
ADD CONSTRAINT [PK_ResortPhoto]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DestinationPoint'
ALTER TABLE [dbo].[DestinationPoint]
ADD CONSTRAINT [PK_DestinationPoint]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'OrderSet'
ALTER TABLE [dbo].[OrderSet]
ADD CONSTRAINT [PK_OrderSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Order_ID], [OrderPrice_ID] in table 'OrderOrderPrice'
ALTER TABLE [dbo].[OrderOrderPrice]
ADD CONSTRAINT [PK_OrderOrderPrice]
    PRIMARY KEY NONCLUSTERED ([Order_ID], [OrderPrice_ID] ASC);
GO

-- Creating primary key on [Order_ID], [Hotel_ID] in table 'OrderHotel'
ALTER TABLE [dbo].[OrderHotel]
ADD CONSTRAINT [PK_OrderHotel]
    PRIMARY KEY NONCLUSTERED ([Order_ID], [Hotel_ID] ASC);
GO

-- Creating primary key on [Order_ID], [Contragent_ID] in table 'OrderContragent'
ALTER TABLE [dbo].[OrderContragent]
ADD CONSTRAINT [PK_OrderContragent]
    PRIMARY KEY NONCLUSTERED ([Order_ID], [Contragent_ID] ASC);
GO

-- Creating primary key on [ServiceForHotel_ID], [Service_ID] in table 'ServiceForHotelService'
ALTER TABLE [dbo].[ServiceForHotelService]
ADD CONSTRAINT [PK_ServiceForHotelService]
    PRIMARY KEY NONCLUSTERED ([ServiceForHotel_ID], [Service_ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Country_ID] in table 'Resort'
ALTER TABLE [dbo].[Resort]
ADD CONSTRAINT [FK_CountryResort]
    FOREIGN KEY ([Country_ID])
    REFERENCES [dbo].[Country]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CountryResort'
CREATE INDEX [IX_FK_CountryResort]
ON [dbo].[Resort]
    ([Country_ID]);
GO

-- Creating foreign key on [Order_ID] in table 'OrderOrderPrice'
ALTER TABLE [dbo].[OrderOrderPrice]
ADD CONSTRAINT [FK_OrderOrderPrice_Order]
    FOREIGN KEY ([Order_ID])
    REFERENCES [dbo].[Order]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [OrderPrice_ID] in table 'OrderOrderPrice'
ALTER TABLE [dbo].[OrderOrderPrice]
ADD CONSTRAINT [FK_OrderOrderPrice_OrderPrice]
    FOREIGN KEY ([OrderPrice_ID])
    REFERENCES [dbo].[OrderPrice]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderOrderPrice_OrderPrice'
CREATE INDEX [IX_FK_OrderOrderPrice_OrderPrice]
ON [dbo].[OrderOrderPrice]
    ([OrderPrice_ID]);
GO

-- Creating foreign key on [User_ID] in table 'Order'
ALTER TABLE [dbo].[Order]
ADD CONSTRAINT [FK_UserOrder]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserOrder'
CREATE INDEX [IX_FK_UserOrder]
ON [dbo].[Order]
    ([User_ID]);
GO

-- Creating foreign key on [Customer_ID] in table 'Passport'
ALTER TABLE [dbo].[Passport]
ADD CONSTRAINT [FK_CustomerPassport]
    FOREIGN KEY ([Customer_ID])
    REFERENCES [dbo].[Customer]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomerPassport'
CREATE INDEX [IX_FK_CustomerPassport]
ON [dbo].[Passport]
    ([Customer_ID]);
GO

-- Creating foreign key on [Order_ID] in table 'OrderHistory'
ALTER TABLE [dbo].[OrderHistory]
ADD CONSTRAINT [FK_OrderOrderHistory]
    FOREIGN KEY ([Order_ID])
    REFERENCES [dbo].[Order]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderOrderHistory'
CREATE INDEX [IX_FK_OrderOrderHistory]
ON [dbo].[OrderHistory]
    ([Order_ID]);
GO

-- Creating foreign key on [Resort_ID] in table 'Hotel'
ALTER TABLE [dbo].[Hotel]
ADD CONSTRAINT [FK_ResortHotel]
    FOREIGN KEY ([Resort_ID])
    REFERENCES [dbo].[Resort]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ResortHotel'
CREATE INDEX [IX_FK_ResortHotel]
ON [dbo].[Hotel]
    ([Resort_ID]);
GO

-- Creating foreign key on [Order_ID] in table 'OrderHotel'
ALTER TABLE [dbo].[OrderHotel]
ADD CONSTRAINT [FK_OrderHotel_Order]
    FOREIGN KEY ([Order_ID])
    REFERENCES [dbo].[Order]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Hotel_ID] in table 'OrderHotel'
ALTER TABLE [dbo].[OrderHotel]
ADD CONSTRAINT [FK_OrderHotel_Hotel]
    FOREIGN KEY ([Hotel_ID])
    REFERENCES [dbo].[Hotel]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderHotel_Hotel'
CREATE INDEX [IX_FK_OrderHotel_Hotel]
ON [dbo].[OrderHotel]
    ([Hotel_ID]);
GO

-- Creating foreign key on [Order_ID] in table 'OrderContragent'
ALTER TABLE [dbo].[OrderContragent]
ADD CONSTRAINT [FK_OrderContragent_Order]
    FOREIGN KEY ([Order_ID])
    REFERENCES [dbo].[Order]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Contragent_ID] in table 'OrderContragent'
ALTER TABLE [dbo].[OrderContragent]
ADD CONSTRAINT [FK_OrderContragent_TravelAgency]
    FOREIGN KEY ([Contragent_ID])
    REFERENCES [dbo].[TravelAgency]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderContragent_TravelAgency'
CREATE INDEX [IX_FK_OrderContragent_TravelAgency]
ON [dbo].[OrderContragent]
    ([Contragent_ID]);
GO

-- Creating foreign key on [ServiceGroup_ID] in table 'Service'
ALTER TABLE [dbo].[Service]
ADD CONSTRAINT [FK_ServiceGroupService]
    FOREIGN KEY ([ServiceGroup_ID])
    REFERENCES [dbo].[ServiceGroup]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServiceGroupService'
CREATE INDEX [IX_FK_ServiceGroupService]
ON [dbo].[Service]
    ([ServiceGroup_ID]);
GO

-- Creating foreign key on [ServiceForHotel_ID] in table 'ServiceForHotelService'
ALTER TABLE [dbo].[ServiceForHotelService]
ADD CONSTRAINT [FK_ServiceForHotelService_ServiceForHotel]
    FOREIGN KEY ([ServiceForHotel_ID])
    REFERENCES [dbo].[ServiceForHotel]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Service_ID] in table 'ServiceForHotelService'
ALTER TABLE [dbo].[ServiceForHotelService]
ADD CONSTRAINT [FK_ServiceForHotelService_Service]
    FOREIGN KEY ([Service_ID])
    REFERENCES [dbo].[Service]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServiceForHotelService_Service'
CREATE INDEX [IX_FK_ServiceForHotelService_Service]
ON [dbo].[ServiceForHotelService]
    ([Service_ID]);
GO

-- Creating foreign key on [Hotel_ID] in table 'ServiceForHotel'
ALTER TABLE [dbo].[ServiceForHotel]
ADD CONSTRAINT [FK_HotelServiceForHotel]
    FOREIGN KEY ([Hotel_ID])
    REFERENCES [dbo].[Hotel]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HotelServiceForHotel'
CREATE INDEX [IX_FK_HotelServiceForHotel]
ON [dbo].[ServiceForHotel]
    ([Hotel_ID]);
GO

-- Creating foreign key on [Service_ID] in table 'ServiceVariant'
ALTER TABLE [dbo].[ServiceVariant]
ADD CONSTRAINT [FK_ServiceServiceVariant]
    FOREIGN KEY ([Service_ID])
    REFERENCES [dbo].[Service]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServiceServiceVariant'
CREATE INDEX [IX_FK_ServiceServiceVariant]
ON [dbo].[ServiceVariant]
    ([Service_ID]);
GO

-- Creating foreign key on [Hotel_ID] in table 'HotelPhoto'
ALTER TABLE [dbo].[HotelPhoto]
ADD CONSTRAINT [FK_HotelHotelPhoto]
    FOREIGN KEY ([Hotel_ID])
    REFERENCES [dbo].[Hotel]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HotelHotelPhoto'
CREATE INDEX [IX_FK_HotelHotelPhoto]
ON [dbo].[HotelPhoto]
    ([Hotel_ID]);
GO

-- Creating foreign key on [Customer_ID] in table 'Scan'
ALTER TABLE [dbo].[Scan]
ADD CONSTRAINT [FK_CustomerScan]
    FOREIGN KEY ([Customer_ID])
    REFERENCES [dbo].[Customer]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomerScan'
CREATE INDEX [IX_FK_CustomerScan]
ON [dbo].[Scan]
    ([Customer_ID]);
GO

-- Creating foreign key on [Resort_ID] in table 'ResortPhoto'
ALTER TABLE [dbo].[ResortPhoto]
ADD CONSTRAINT [FK_ResortResortPhoto]
    FOREIGN KEY ([Resort_ID])
    REFERENCES [dbo].[Resort]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ResortResortPhoto'
CREATE INDEX [IX_FK_ResortResortPhoto]
ON [dbo].[ResortPhoto]
    ([Resort_ID]);
GO

-- Creating foreign key on [NearestHotel_ID] in table 'Hotel'
ALTER TABLE [dbo].[Hotel]
ADD CONSTRAINT [FK_RelatredHotel]
    FOREIGN KEY ([NearestHotel_ID])
    REFERENCES [dbo].[Hotel]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RelatredHotel'
CREATE INDEX [IX_FK_RelatredHotel]
ON [dbo].[Hotel]
    ([NearestHotel_ID]);
GO

-- Creating foreign key on [Order_ID] in table 'DestinationPoint'
ALTER TABLE [dbo].[DestinationPoint]
ADD CONSTRAINT [FK_OrderDestinationPoint]
    FOREIGN KEY ([Order_ID])
    REFERENCES [dbo].[Order]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderDestinationPoint'
CREATE INDEX [IX_FK_OrderDestinationPoint]
ON [dbo].[DestinationPoint]
    ([Order_ID]);
GO

-- Creating foreign key on [DestinationPoint_ID] in table 'Hotel'
ALTER TABLE [dbo].[Hotel]
ADD CONSTRAINT [FK_DestinationPointHotel]
    FOREIGN KEY ([DestinationPoint_ID])
    REFERENCES [dbo].[DestinationPoint]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DestinationPointHotel'
CREATE INDEX [IX_FK_DestinationPointHotel]
ON [dbo].[Hotel]
    ([DestinationPoint_ID]);
GO

-- Creating foreign key on [Customer_ID] in table 'OrderSet'
ALTER TABLE [dbo].[OrderSet]
ADD CONSTRAINT [FK_CustomerOrderSet]
    FOREIGN KEY ([Customer_ID])
    REFERENCES [dbo].[Customer]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomerOrderSet'
CREATE INDEX [IX_FK_CustomerOrderSet]
ON [dbo].[OrderSet]
    ([Customer_ID]);
GO

-- Creating foreign key on [Order_ID] in table 'OrderSet'
ALTER TABLE [dbo].[OrderSet]
ADD CONSTRAINT [FK_OrderOrderSet]
    FOREIGN KEY ([Order_ID])
    REFERENCES [dbo].[Order]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderOrderSet'
CREATE INDEX [IX_FK_OrderOrderSet]
ON [dbo].[OrderSet]
    ([Order_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------